package com.angel.web.health;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.angel.core.util.JsonUtil;
import com.angel.core.util.Pager;
import com.angel.health.BuzCompany;
import com.angel.provider.health.BuzCompanyProvider;

/**
 * 单位管理
 * @author gao
 *
 */
@Controller
@RequestMapping("company")
public class BuzCompanyController {
	
	@Autowired
	BuzCompanyProvider companyService;

	@RequestMapping("index")
	public String index(HttpServletRequest request,@ModelAttribute("buzCompany")BuzCompany buzCompany,Pager pager){
		Pager bean= companyService.findAll(buzCompany,pager);
		request.setAttribute("pager", bean);
		return "";
	}
	
	@ResponseBody
	@RequestMapping("save")
	public String save(HttpServletRequest request,@ModelAttribute("buzCompany") BuzCompany buzCompany){
		String username = (String) request.getSession().getAttribute("userName");
		buzCompany.setCreateBy(username);
		buzCompany.setUpdateBy(username);
		int i = companyService.insert(buzCompany);
		return JsonUtil.toJson(i);
	}
	
	@ResponseBody
	@RequestMapping("update")
	public String update(@ModelAttribute("buzCompany")BuzCompany buzCompany){
		int i = companyService.updateById(buzCompany);
		return JsonUtil.toJson(i);
	}
	
	@RequestMapping("/findAllCompany")
	@ResponseBody
	public String findAllCompany(){
		List<BuzCompany> list = companyService.findAllCompany();
		return JsonUtil.toJson(list);
	}
	
}
